const path = require('path');
const resolve = (dir) => path.join(__dirname, dir);
const IS_PROD = ['production', 'prod'].includes(process.env.NODE_ENV);

module.exports = {
    publicPath: './',
    // assetsPublicPath: './',
    assetsDir: 'assets',
    productionSourceMap: false,
    // 以下是pwa配置
    pwa: {
        iconPaths: {
            favicon32: 'favicon.ico',
            favicon16: 'favicon.ico',
            appleTouchIcon: 'favicon.ico',
            maskIcon: 'favicon.ico',
            msTileImage: 'favicon.ico'
        }
    },
    devServer: {
        open: IS_PROD, // 生产环境才使用浏览器自动打开
        https: false,
        port: 8300,
        proxy: {
            '/localApi': {
                // 本地
                target: process.env.VUE_APP_SRC || 'http://127.0.0.1:8080',
                changeOrigin: process.env.NODE_ENV === 'development' ? true : false, // 开发环境才开启反向代理, 运行(生产)环境不开启
                pathRewrite: {
                    '^/localApi': '/'
                }
            }
        }
    },
    chainWebpack: config => {
        // 添加别名
        config.resolve.alias
            .set('@', resolve('src'))
            .set('assets', resolve('src/assets'))
            .set('components', resolve('src/components'))
            .set('layout', resolve('src/layout'))
            .set('base', resolve('src/base'))
            .set('static', resolve('src/static'))
            .set('utils', resolve('src/utils'))
            .set('common', resolve('src/components/common'));
    }
}